package com.atguigu.guli.service.edu.controller.api;


import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.edu.entity.Teacher;
import com.atguigu.guli.service.edu.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 讲师 前端控制器
 * </p>
 *
 * @author leo
 * @since 2021-11-24
 */
@RestController

@RequestMapping("/api/edu/teacher")
public class ApiTeacherController {
    @Autowired
    TeacherService teacherService;
    //1.根据id查询讲师详情
    @GetMapping("getById/{teacherId}")
    public R getById(@PathVariable String teacherId){
        return R.ok().data("item" ,teacherService.getById(teacherId) );
    }
    //2.查询所有讲师
//    @ResponseBody
    @GetMapping("list")  //restController中的接口返回值会被转为json
    public R queryAll(){
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return R.ok().data("items",teacherService.list());
    }

    //3.查询热门讲师（按sort降序排列,前4个）
    @GetMapping("getHotTeachers")
    public R getHotTeachers() {
        List<Teacher> teachers = teacherService.getHotTeachers() ;
        return R.ok().data("items",teachers) ;
    }

}

